<template>
  <el-form ref="form" :model="form" label-width="180px">
    <el-form-item label="过审模式">
      <el-switch v-model="form['reviewStatus']"/>
    </el-form-item>
    <el-form-item label="宣传图">
      <ws-upload-single-img v-model="form['picId']" :path="form['picUrl']"/>
    </el-form-item>
    <el-form-item label="标题">
      <el-input v-model="form['name']"/>
    </el-form-item>
    <el-form-item label="简介">
      <el-input v-model="form['brief']" row="4"/>
    </el-form-item>
    <el-form-item label="图文">
      <ws-editor v-model="form['content']"/>
    </el-form-item>
    <el-form-item label="联系电话">
      <el-input v-model="form['mobile']"/>
    </el-form-item>
    <el-form-item label="邮箱">
      <el-input v-model="form['email']"/>
    </el-form-item>
    <el-form-item label="地址">
      <el-input v-model="form['address']"/>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" class="bg-green" @click="submitForm('form')">提交</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
  export default {
    data() {
      return {
        form: {}
      }
    },
    created() {
      this.getSiteConfig()
    },
    methods: {
      getSiteConfig() {
        const url = '../videoAdmin/setting/getDataList'
        const data = {
          type: 'review'
        }
        this.$store.dispatch('GetConnect', { url, data }).then(res => {
          this.form = res.data;
          this.form.reviewStatus = this.form.reviewStatus === '1';
        }).catch(e => {
          this.$message.error(e.msg + ',请刷新或联系管理员')
        })
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            const url = '../videoAdmin/setting/updateData'
            const data = Object.assign({}, this.form)
            data.reviewStatus = data.reviewStatus ? 1 : 0
            data.type = 'review'
            this.$store.dispatch('GetConnect', { url, data }).then(res => {
              this.$message.success(res.msg)
              this.getSiteConfig()
            }).catch(e => {
              this.$message.error(e.msg)
            })
          } else {
            this.$message.error('提交失败,请检查必填项')
          }
        })
      }
    }
  }
</script>

<style lang="scss" type="text/scss" scoped>
  @import '../../../../styles/index.scss';
  .el-form {
      max-width: 900px;
  }
</style>
